package com.csii.branch.activity.server.impl;

import com.csii.activiti.server.abstraction.entity.ActUserDetail;
import com.csii.activiti.server.abstraction.service.ActBasicService;
import com.csii.core.api.Result;
import com.csii.core.system.vo.LoginUser;
import com.csii.user.service.ISysUserBaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ActBasicServiceImpl implements ActBasicService {

    @Autowired
    private ISysUserBaseService sysUserBaseService;

    @Override
    public ActUserDetail getCurrentLoginUser() {
        ActUserDetail actUserDetail = new ActUserDetail();
        LoginUser loginUser = (LoginUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        actUserDetail.setNickname(loginUser.getRealname());
        actUserDetail.setUsername(loginUser.getUsername());
        Result<List<String>> deptResult = sysUserBaseService.queryDeptCodeByUserId(loginUser.getId());
        if (deptResult != null){
            actUserDetail.setDeptCodes(deptResult.getResult());
        }

        Result<List<String>> roleResult = sysUserBaseService.queryRoleCodeByUserId(loginUser.getId());
        if (roleResult != null){
            actUserDetail.setRoleCodes(roleResult.getResult());
        }
        return actUserDetail;
    }
}
